import axios, {request} from "axios"
import {ElMessage} from "element-plus";

const instance =axios.create({
    timeout:60000,
    headers:{"Content-Type":"application/json"},
    baseURL:'http://localhost:8080'
    //这里要改
})

instance.interceptors.request.use((request)=>{
    var token=localStorage.getItem("token");
    if(token){
        console.log('getToken: ', token)
        request.headers.Authorization=token
    }
    return request;
},(error)=>{
    return Promise.reject(error.message);
})

instance.interceptors.response.use(
    function (response){
        console.log(response);
        console.log(response.status);

        if(response.status===200){
            return Promise.resolve(response.data);
        }else {
            return Promise.reject(response.data);
        }
    },function (error){
        ElMessage.error(error.message);

        return Promise.reject(error);
    }
);

export default instance